package edu.zju.gis.dbfg.fileserver.controller;

import edu.zju.gis.dbfg.common.Result;

import edu.zju.gis.dbfg.common.base.BaseController;
import edu.zju.gis.dbfg.common.constant.CodeConstants;

import edu.zju.gis.dbfg.fileserver.model.search.UserSearch;
import edu.zju.gis.dbfg.fileserver.service.RoleService;
import edu.zju.gis.dbfg.fileserver.model.User;

import edu.zju.gis.dbfg.fileserver.service.UserService;
import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @author Hu
 * @date 2019/8/26
 **/
@CrossOrigin
@Controller
@RequestMapping("/user")
public class UserController extends BaseController<User, UserService, String, UserSearch> {
    @Autowired
    private RoleService roleService;

    /**
     * 用户登陆状态
     *
     * @param session
     * @return userId
     */
    @RequestMapping(value = "/status", method = RequestMethod.GET)
    @ResponseBody
    public Result getloginstatus(HttpSession session) {
        Object userId = session.getAttribute("userId");
        if (userId != null) {
            User user = service.select(String.valueOf(userId));
            return Result.success().setBody(user);
        }
        return Result.error("has not login").setCode(CodeConstants.USER_NOT_EXIST);
    }



}
